package com.lemon.components.ant.project.makers;

import com.lemon.components.ant.project.beans.ModelInfo;
import com.lemon.components.ant.project.beans.SqlParserInfo;
import com.lemon.components.ant.util.ConfigUtil;
import com.lemon.components.ant.util.DruidSQLParser;
import com.lemon.components.ant.util.PathUtil;
import com.lemon.ui.codemaker.component.RecentlyFile;

public class MybatisMaker {
	
	String sql = "SELECT\r\n" + 
			"	boss_user.user_name,\r\n" + 
			"	sys_role.role_name,\r\n" + 
			"	boss_user.is_locked,\r\n" + 
			"	boss_user.user_role_id\r\n" + 
			"FROM\r\n" + 
			"	boss_user\r\n" + 
			"INNER JOIN sys_role ON boss_user.user_role_id = sys_role.id\r\n" + 
			"WHERE\r\n" + 
			"	boss_user.nick = ?\r\n" + 
			"AND boss_user.phone = ?\r\n" + 
			"OR boss_user.create_time > ?\r\n" + 
			"AND boss_user.password < ?\r\n" + 
			"AND boss_user.create_time < CURRENT_TIME\r\n" + 
			"OR sys_role.role_code = ?";

	public void make() {
		DruidSQLParser druidSQLParser = new DruidSQLParser();
		SqlParserInfo sqlParserInfo = druidSQLParser.parseSql(sql);
		
		ModelInfo beanInfo = new ModelInfo();
		ModelMaker beanMaker = new ModelMaker();
		beanInfo.setBeanName(ConfigUtil.getInstance(RecentlyFile.configFilePath).getMethodInfo().getMethodName()+"ReqDto");
		beanInfo.setBeanPath(PathUtil.getInstance(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfo()).getDalPackagePath().getPath()+"mybatis/mymodel/");
		beanInfo.setColumns(sqlParserInfo.getReq());
		beanInfo.setBeanPackage(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfo().getGroupId()+".dal.mybatis.mymodel");
		beanMaker.make(beanInfo);
		
		beanInfo.setBeanName(ConfigUtil.getInstance(RecentlyFile.configFilePath).getMethodInfo().getMethodName()+"RspDto");
		beanInfo.setColumns(sqlParserInfo.getRsp());
		beanMaker.make(beanInfo);
	}
	
	public static void main(String[] args) {
		MybatisMaker mybatisMaker = new MybatisMaker();
		mybatisMaker.make();
	}
}